using System.Windows;

namespace MinoChat.Views.Dialogs;

public partial class InputBox : Window
{
    public InputBox()
    {
        InitializeComponent();
        Owner ??= Application.Current.MainWindow;
        this.UserInputTextBox.Focus();
        this.UserInputTextBox.SelectAll();
    }
    public string? UserInput { get; private set; }
    public InputBox(string prompt,string title,string defaultText = ""):this()
    {
        this.PromptTextBlock.Text = prompt;
        this.Title = title;
        this.UserInputTextBox.Text = defaultText;
        OKButton.IsEnabled = !string.IsNullOrWhiteSpace(defaultText);
    }
    private void UserInputTextBox_OnTextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
    {
        OKButton.IsEnabled = !string.IsNullOrWhiteSpace(UserInputTextBox.Text);
    }
    private void OKButton_OnClick(object sender, RoutedEventArgs e)
    {
       UserInput = UserInputTextBox.Text;
       this.DialogResult = true;
    }
    private void CancelButton_OnClick(object sender, RoutedEventArgs e)
    {
      this.DialogResult = false;
    }
}
